#include <iostream>
#include "newton.h"


class DerivedFunction : public FunctionBase {
public:
    double operator()(double x)  {
        return x;  //
    }
};

int main(void){
  double a3[10] = {0, 0, 3, 3, 5, 5, 8, 8, 13, 13}; // 时间 t
  double a4[10] = {0, 75, 225, 77, 383, 80, 623, 74, 993, 72}; // 位置 s(t)

  Newton_1 new_2(a3,10,a4);

  
  double r1 = new_2.interpolate(10);
  double r2 = (new_2.interpolate(10+1e-8) - new_2.interpolate(10)) / 1e-8; // 对位置函数求导来计算速度

  std::cout << "t = 10s 时的位置为：" << r1 << " feet" << std::endl;
  std::cout << "t = 10s 时的速度为：" << r2 << " feet per second" << std::endl;
  
  double v = (new_2.interpolate(12.5+1e-8) - new_2.interpolate(12.5)) / 1e-8;
  std::cout << "t = 12.5s 时的速度为：" << v << " feet per second" << std::endl;
  
  if(v > 81) {
      std::cout << "速度大于 81 feet per second，所以会超速。" << std::endl;
  } else {
      std::cout << "速度不会超速。" << std::endl;
  }
  
  return 0;
}
